﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;

namespace SzCourt.WebSite.manager
{
    public partial class ModifyPassword : System.Web.UI.Page
    {
        private string _OldPassword = string.Empty;
        private string _Password = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            if (!this.IsPostBack)
            {
                getParam();
                if (this._OldPassword.Length > 0 && this._Password.Length > 0)
                {
                    editPassword();
                }
            }
        }

        //获取参数值
        private void getParam()
        {
            this._OldPassword = string.IsNullOrEmpty(Request.Form["txtOldPassWord"]) ? "" : Request.Form["txtOldPassWord"];
            this._Password = string.IsNullOrEmpty(Request.Form["txtPassword"]) ? "" : Request.Form["txtPassword"];
            
        }

        private void editPassword()
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            AdminUser bll = new AdminUser();
            bool result = (bool)bll.EditPWD(AdminSession.SessionBox.GetUserSession().UserName,this._OldPassword, this._Password);

            if (result)
            {
                this.spMessage.InnerHtml = "修改密码成功！";
            }
            else
            {
                this.spMessage.InnerHtml = "修改密码失败，请检查旧密码是否正确！";
            }
        }

    }
}